package com.jiazhong.shixi.shixixiangmu2025.bookstore.controller;

import com.jiazhong.shixi.shixixiangmu2025.bookstore.bean.Shopping_cart;
import com.jiazhong.shixi.shixixiangmu2025.bookstore.mapper.ShoppingCartMapper;
import com.jiazhong.shixi.shixixiangmu2025.bookstore.util.JsonResult;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import java.util.List;

@RequestMapping("/shopping_cart")
@RestController
public class ShoppingCartController {
    @Resource
    private ShoppingCartMapper shoppingCartMapper;

    @RequestMapping("/find")
    public JsonResult findByUserId(String user_id) {
        List<Shopping_cart> list = shoppingCartMapper.findByUserId(user_id);
        JsonResult result = new JsonResult(true, 200, list, "");
        return result;
    }
    @RequestMapping("/add")
    public JsonResult addCart(Shopping_cart sc){
        shoppingCartMapper.add(sc);
        JsonResult result = new JsonResult(true, 200, "success", "");
        return result;
    }
    @RequestMapping("/update")
    public JsonResult updateCart(Shopping_cart sc){
        shoppingCartMapper.update(sc);
        JsonResult result = new JsonResult(true, 200, "success", "");
        return result;
    }
    @RequestMapping("/remove1")
    public JsonResult remove1(Shopping_cart sc){
        shoppingCartMapper.remove1(sc);
        JsonResult result = new JsonResult(true, 200, "success", "");
        return result;
    }
    @RequestMapping("/remove2")
    public JsonResult remove2(Shopping_cart sc){
        shoppingCartMapper.remove2(sc);
        JsonResult result = new JsonResult(true, 200, "success", "");
        return result;
    }
}